package com.frinder.seata.data.domain.web;

import com.frinder.seata.data.base.Result;
import com.frinder.seata.data.base.PageWrapper;
import com.frinder.seata.data.base.ModelWrapper;
import com.frinder.seata.data.domain.model.TbOrder;
import com.frinder.seata.data.domain.service.ITbOrderService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2020/08/18.
*/
@RestController
@RequestMapping("/tbOrder")
public class TbOrderController {
    @Resource
    private ITbOrderService tbOrderService;

    @ApiOperation(value = "添加 TbOrder")
    @PostMapping("/add")
    public Result add(@RequestBody TbOrder tbOrder) {
        tbOrderService.save(tbOrder);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 删除 TbOrder")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        tbOrderService.deleteById(id);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 ids 批量删除 TbOrder")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        tbOrderService.deleteByIds(ids);
        return Result.defSuccess();
    }

    @ApiOperation(value = "更新 TbOrder")
    @PostMapping("/update")
    public Result update(@RequestBody TbOrder tbOrder) {
        tbOrderService.update(tbOrder);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 查询 TbOrder")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        TbOrder tbOrder = tbOrderService.findById(id);
        return Result.dataSuccess(tbOrder);
    }

    @ApiOperation(value = "按条件查询 TbOrder")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<TbOrder> wrapper) {
        List<TbOrder> list = tbOrderService.findByModelWrapper(wrapper);
        return Result.dataSuccess(list);
    }

    @ApiOperation(value = "按条件分页查询 TbOrder")
    @PostMapping("/page")
    public Result page(@RequestBody PageWrapper<TbOrder> page) {
        PageInfo pageInfo = tbOrderService.page(page);
        return Result.dataSuccess(pageInfo);
    }
}
